package com.balance.anole.erp.component;

import java.util.List;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
import org.eclipse.swt.widgets.Composite;

import com.balance.anole.common.to.CodeLookTO;
import com.balance.anole.erp.common.provider.CodeLookComboLabelProvider;

public class ComboViewerEditingSupport extends AbstractEditingSupport {

	public ComboViewerEditingSupport(ColumnViewer viewer, DataBindingContext dbc, List<CodeLookTO> input, String propertyName) {
		super(viewer, dbc);
		ComboBoxViewerCellEditor cbvc = new ComboBoxViewerCellEditor((Composite) viewer.getControl());
		cbvc.setLabelProvider(new CodeLookComboLabelProvider());
		cbvc.setContenProvider(new ArrayContentProvider());
		cbvc.setInput(input);
		cellEditor = cbvc;
		this.propertyName = propertyName;
	}

	@Override
	protected IObservableValue doCreateCellEditorObservable(
			CellEditor cellEditor) {
		return ViewersObservables.observeSingleSelection(((ComboBoxViewerCellEditor)cellEditor).getViewer());
	}
}
